﻿// Copyright © Armen Kirakosyan
// armen@kirakosyan.com

namespace Sample
{
    using System;

    class Program
    {
        static void Main()
        {
            Validator.ValidatorResult result;

            Console.Write("Please enter public url to check [http://www.bing.com]: ");
            var url = Console.ReadLine();
            if (String.IsNullOrWhiteSpace(url))
            {
                url = "http://www.bing.com";
            }

            Console.WriteLine("Please wait checking {0} ....", url);
            try
            {
                // validate with URL
                result = Validator.Client.Check(new Uri(url, UriKind.Absolute));

                // validate with HTML
                //WebClient wc = new WebClient();
                //var html = wc.DownloadString(url);
                //result = Validator.Client.Check(wc.DownloadString(url));
                //wc.Dispose();
            }
            catch(Exception exception)
            {
                Console.WriteLine("Error: {0}", exception.Message);
                Console.ReadKey();
                return;
            }

            // Show result
            Console.WriteLine();
            //Console.WriteLine("Response: {0}", result.MarkupValidationResponse);
            Console.WriteLine("Validity: {0}", result.Validity);
            Console.WriteLine("Charset: {0}", result.Charset);
            Console.WriteLine("Doctype: {0}", result.DocType);
            Console.WriteLine("Number of errors: {0}", result.ErrorCount);

            if (!result.Validity)
            {
                Console.WriteLine("Press a key to show all errors");
                Console.ReadKey();
            }

            foreach (var error in result.Errors)
            {
                Console.WriteLine(error);
            }

            Console.WriteLine("Done. Press a key to close.");
            Console.ReadKey();
        }
    }
}
